package com.dobby.logger.system.controller;


import com.dobby.logger.common.OpenPage;
import com.dobby.logger.system.service.SystemLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created by lgq on 2015/5/13.
 */
@Controller
@RequestMapping(value = "/systemLog")
public class SystemLogController {

    @Autowired
    private SystemLogService sysLogHandler;


    /**
     * 跳转到list页面
     */
    @RequestMapping(value = "/list")
    public String list(@RequestParam(value = "companyId", required = false, defaultValue = "") String companyId,
                       @RequestParam(value = "userId", required = false, defaultValue = "") String userId,
                       @RequestParam(value = "startDate", required = false, defaultValue = "") String startDate,
                       @RequestParam(value = "endDate", required = false, defaultValue = "") String endDate,
                       @RequestParam(value = "pageNo", required = false, defaultValue = "1") int pageNo,
                       @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
                        ModelMap modelMap) {
        OpenPage openPage = new OpenPage();
        openPage.setPageNo(pageNo);
        openPage.setPageSize(pageSize);

        openPage = sysLogHandler.getColumnByCondition(companyId, userId, startDate, endDate, openPage);
        modelMap.addAttribute("sysLogOpenPage", openPage);
        modelMap.addAttribute("userId", userId);
        modelMap.addAttribute("companyId", companyId);
        modelMap.addAttribute("startDate", startDate);
        modelMap.addAttribute("endDate", endDate);
        return "/syslist";
    }

    @RequestMapping(value = "/delete")
    public String delete(@RequestParam String id) {
        String[] idArray = StringUtils.split(id, ",");
        sysLogHandler.deleteColumns(idArray);
        return "redirect:/controller/sysLog/list";
    }


}
